package jsu.lipengcheng.trafficnet.controlle.user;

import jsu.lipengcheng.trafficnet.common.BeanThread;
import jsu.lipengcheng.trafficnet.common.Result;
import jsu.lipengcheng.trafficnet.pojo.Activity;
import jsu.lipengcheng.trafficnet.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/activity")
public class UserActivityControlle {
    @Autowired
    private ActivityService activityService;

    /**
     * 根据状态查询活动
     * @param status
     * @return
     */
    @GetMapping("/all")
    public Result all(Integer status) {
        List<Activity> activityList = activityService.selectbystatus(status);
        return Result.success(activityList);
    }

    /**
     * 参加活动
     * @param id
     * @return
     */
    @PostMapping("/insert/{id}")
    public Result insert(@PathVariable Integer id) {
        activityService.insertuser(id);
        return Result.success();
    }
    @GetMapping("/join")
    public Result findjoin(){
        Integer userid = BeanThread.get();
        List<Activity> activityList=activityService.findactivitybyuserid(userid);
        return Result.success(activityList);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        Activity selectbyid = activityService.selectbyid(id);
        return Result.success(selectbyid);
    }
}
